from sqlalchemy import ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from ...core.models.enums.deposit import DepositStatus
from .base import TimedBaseModel


class Deposit(TimedBaseModel):
    __tablename__ = "deposit"
    __mapper_args__ = {"eager_defaults": True}

    id: Mapped[int] = mapped_column(primary_key=True)
    status: Mapped[DepositStatus] = mapped_column(server_default="waiting_payment")
    summ: Mapped[float] = mapped_column(nullable=False)
    user = relationship("User", back_populates="deposits")
    user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))
    account = relationship("Account", back_populates="deposits")
    account_id: Mapped[int] = mapped_column(ForeignKey("account.id"))
    payment_method = relationship("PaymentDetails", back_populates="deposits")
    payment_method_id: Mapped[int] = mapped_column(
        ForeignKey("payment_details.id"), nullable=True
    )
    invoice_screenshot_path: Mapped[str | None] = mapped_column(String(255))

    def __repr__(self):
        return f"<Оплата №{self.id} {self.created_at}>"

    def __str__(self):
        return self.__repr__()
